﻿using System.Windows.Media;
using Styx.Common;

namespace Portal.Helpers
{
        static class Log
        {
            private static string _lastMessage = "";
            public static string _char = "~";

            public static void Info(string message, params object[] args)
            {
                try
                {
                    Logging.Write(Colors.LightSkyBlue, "[Portal] {0}", string.Format(message, args));
                }
                catch {}
            }

            public static void Debug(string message, params object[] args)
            {
                try
                {
                Logging.Write(LogLevel.Diagnostic, Colors.DodgerBlue, "[Portal {1} Debug] {0}", string.Format(message, args), _char);
                }
                catch {}
            }

            public static void Fail(string message, params object[] args)
            {
                try
                {
                Logging.Write(LogLevel.Diagnostic, Colors.Crimson, "[Portal {1} Fail] {0}", string.Format(message, args), _char);
                }
                catch {}
            }

            public static void Orange(string message, params object[] args)
            {
                try
                {
                Logging.Write(LogLevel.Diagnostic, Colors.Orange, "[Portal] {0}", string.Format(message, args));
                }
                catch {}
            }

            public static void Green(string message, params object[] args)
            {
                try
                {
                Logging.Write(LogLevel.Diagnostic, Colors.Green, "[Portal] {0}", string.Format(message, args));
                }
                catch {}
            }

            public static void PrintNoDuplicate(string message, params object[] args)
            {
                string formatted = string.Format(message, args);

                if (_lastMessage == formatted) return;
                _lastMessage = formatted;
                Logging.Write(LogLevel.Diagnostic, Colors.Aqua, "[Portal] {0}", formatted);
            }


            public static void LogToGame(string message, params object[] args)
            {
                string formatted = string.Format(message, args).Replace("'", "\'").Replace("!", ".");
                
                if (_lastMessage == formatted) return;
                _lastMessage = formatted;

                Styx.WoWInternals.Lua.DoString(@"print('\124cFF29B6F2[Portal]\124cFFFFFFFF " + Lua.RealLuaEscape(formatted) + "')");
            }


        }
}
